package com.kcl.dfss;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MatchingCarActivity extends Activity implements OnClickListener{

	private static final String tag = "MatchingCarActivity";
	private LinearLayout matching_car_back,layout_selectcar;
	private Button btn_carnext;
	private String braid,serid,modid,userid;
	private SharedPreferences camcfg = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_matching_car);
		
		matching_car_back = (LinearLayout) findViewById(R.id.matching_car_back);
		layout_selectcar = (LinearLayout) findViewById(R.id.layout_selectcar);
		btn_carnext = (Button) findViewById(R.id.btn_carnext);
		
		matching_car_back.setOnClickListener(this);
		layout_selectcar.setOnClickListener(this);
		btn_carnext.setOnClickListener(this);
		
		SharedPreferences preferences = getSharedPreferences("shared_login", 0);
		userid = preferences.getString("userid", "");
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.matching_car_back:
			finish();
			break;
		case R.id.layout_selectcar:
			startActivity(new Intent(MatchingCarActivity.this, SelectCarActivity.class));
			break;
		case R.id.btn_carnext:
			if(braid!=""&&serid!=""&&modid!=""){
				startActivity(new Intent(MatchingCarActivity.this,MatchingInstallActivity.class));
			}else{
				Toast.makeText(MatchingCarActivity.this, "请先选择车型", Toast.LENGTH_SHORT).show();
			}
			break;
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		camcfg = getSharedPreferences("camcfg", 0);
		braid = camcfg.getString("brandID", "");
		serid = camcfg.getString("seriesID", "");
		modid = camcfg.getString("modelID", "");
		
		Log.i(tag, "brandID:"+braid);
		Log.i(tag, "seriesID:"+serid);
		Log.i(tag, "modelID:"+modid);
		
		if(braid!=""&&serid!=""&&modid!=""){
			btn_carnext.setEnabled(true);
			btn_carnext.setBackgroundResource(R.drawable.register_select);
		}else{
			btn_carnext.setEnabled(true);
			btn_carnext.setBackgroundResource(R.drawable.changepwd_noclick);
		}
	}
	
	

}
